package com.framework.modules.job.task;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.framework.common.config.SystemConfigName;
import com.framework.common.utils.QuickHelper;
import com.framework.modules.base.entity.UserVipinfoEntity;
import com.framework.modules.base.service.UserVipinfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

@Component("resetDailyMatchingServiceTask")
public class ResetDailyMatchingServiceTask {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private UserVipinfoService userVipinfoService;

    public void run(String params) {

        logger.info("当前任务参数为：" + params);

        JSONObject matchingConfig =QuickHelper.getConfigJSONObject(SystemConfigName.ASSETS_MATCHING_DAILY_LIMIT);
        UserVipinfoEntity vipinfo = new UserVipinfoEntity();
        vipinfo.setDailyInterestSearchCount(matchingConfig.getIntValue("interest"));
        vipinfo.setDailySenceSearchCount(matchingConfig.getIntValue("sence"));
        vipinfo.setDailyVoiceSearchCount(matchingConfig.getIntValue("voice"));
        vipinfo.setDailyLocationSearchCount(matchingConfig.getIntValue("location"));

        Boolean result = userVipinfoService.update(vipinfo, new EntityWrapper<UserVipinfoEntity>().gt("uid", 0));

        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        logger.info(String.format("任务完成 resetDailyMatchingServiceTask.run 返回值： %s", result));
    }

    public void test2() {
        logger.info("我是不带参数的test2方法，正在被执行");
    }
}
